#define _CRT_SECURE_NO_WARNINGS 1


#include<vector>
#include<iostream>

using namespace std;

void duplicateZeros(vector<int>& arr)
{
	int size = arr.size();
	int cur = 0, dest = -1;
	while (dest < size)
	{
		if (arr[cur] != 0)
		{
			dest++;
		}
		else
		{
			dest += 2;
		}
		if (dest >= size - 1)
		{
			break;
		}
		cur++;
	}
	if (dest == size)
	{
		arr[size - 1] = 0;
		cur--;
		dest -= 2;
	}
	while (dest >= 0)
	{
		if (arr[cur] != 0)
		{
			arr[dest--] = arr[cur];
		}
		else
		{
			arr[dest--] = 0;
			arr[dest--] = 0;
		}
		cur--;
	}
}

int main()
{
	vector<int> v = { 8,4,5,0,0,0,0,7 };
	duplicateZeros(v);
	for (auto& e : v)
	{
		cout << e << ' ';
	}
	cout << endl;

	return 0;
}